package cn.yj.quartz.utils;

import org.quartz.Scheduler;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author 永健
 * @since 2022-01-14 16:41
 */
@Component
public class SpringBeanUtil implements ApplicationContextAware {

    private static ApplicationContext app;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        app = applicationContext;
    }

    public static <T> T getBean(Class<T> aClass){
        return (T)app.getBean(aClass);
    }

    public static <T> T getBean(String beanName){
        return (T)app.getBean(beanName);
    }
}
